package com.nari.ncps.screen.controller;

import com.nari.ncps.screen.common.pojo.ApiResponse;
import com.nari.ncps.screen.service.ne.*;
import com.nari.ncps.screen.vo.ne.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 能源消费表 前端控制器
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Tag(name = "新能源产业", description = "新能源产业")
@RestController
@RequestMapping("/ne")
public class NeController {

    @Resource
    private NeProdoperPowerGsService neProdoperPowerGsService;

    @Resource
    private NeProdoperPowerTotalService neProdoperPowerTotalService;

    @Resource
    private NeProdoperElectricEffService neProdoperElectricEffService;

    @Resource
    private NeProdoperTimeRateService neProdoperTimeRateService;

    @Resource
    private NeProdoperEastPriceService neProdoperEastPriceService;

    @Resource
    private NeProdoperWestPriceService neProdoperWestPriceService;

    @Resource
    private NeProdoperSalesIncomeService neProdoperSalesIncomeService;

    @Resource
    private NeProdoperSalesPurchaseService neProdoperSalesPurchaseService;

    @Resource
    private NeOverviewItemService neOverviewItemService;

    @Resource
    private NeOpermonEqpStateService neOpermonEqpStateService;

    @Resource
    private NeOpermonWindStateService neOpermonWindStateService;

    @Resource
    private NeOpermonPvStateService neOpermonPvStateService;

    @Resource
    private NeOpermonRtLoadService neOpermonRtLoadService;

    @Resource
    private NeOpermonRtPvService neOpermonRtPvService;

    @Resource
    private NeOpermonRtWindService neOpermonRtWindService;

    @Resource
    private NeSafetyenvCoalReduceService neSafetyenvCoalReduceService;

    @Resource
    private NeSafetyenvRiskTaskService neSafetyenvRiskTaskService;

    @Resource
    private NeSafetyenvNetRankService neSafetyenvNetRankService;
    @Resource
    private NeWindFieldBasicInfoService windFieldBasicInfoService;
    @Resource
    private NePopupSafeService nePopupSafeService;
    @Resource
    private NePopupNetOutputService nePopupNetOutputService;

    @Resource
    private NeWindResourceService neWindResourceService;


    @Operation(summary = "生产经营-发电情况-年发电完成情况", description = "生产经营-发电情况-年发电完成情况")
    @GetMapping(value = "/operation/power-generation/annual")
    public ApiResponse<List<NePowerGenerationAnnualVO>> getAnnualPowerGeneration(@RequestParam(value = "year", required = false) Integer year) {
        List<NePowerGenerationAnnualVO> resultList = neProdoperPowerGsService.getAnnualPowerGeneration(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-发电情况-月发电完成情况", description = "生产经营-发电情况-月发电完成情况")
    @GetMapping(value = "/operation/power-generation/monthly")
    public ApiResponse<List<NePowerGenerationMonthlyVO>> getMonthlyPowerGeneration(@RequestParam(value = "year", required = false) Integer year) {
        List<NePowerGenerationMonthlyVO> resultList = neProdoperPowerGsService.getMonthlyPowerGeneration(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-发电情况-日发电完成情况", description = "生产经营-发电情况-日发电完成情况")
    @GetMapping(value = "/operation/power-generation/daily")
    public ApiResponse<List<NePowerGenerationDailyVO>> getDailyPowerGeneration(@RequestParam(value = "year", required = false) Integer year) {
        List<NePowerGenerationDailyVO> resultList = neProdoperPowerGsService.getDailyPowerGeneration(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-生产情况-发电量月度同比情况", description = "生产经营-生产情况-发电量年度同比情况")
    @GetMapping(value = "/operation/production/yoy-rate")
    public ApiResponse<List<NePowerGenerationYoyVO>> getPowerGenerationYoyRate(@RequestParam(value = "year", required = false) Integer year) {
        List<NePowerGenerationYoyVO> resultList = neProdoperPowerTotalService.getPowerGenerationYoyRate(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-生产情况-电力生产效率", description = "生产经营-生产情况-电力生产效率")
    @GetMapping(value = "/operation/production/efficiency")
    public ApiResponse<List<NeElectricEfficiencyVO>> getElectricProductionEfficiency(@RequestParam(value = "year", required = false) Integer year) {
        List<NeElectricEfficiencyVO> resultList = neProdoperElectricEffService.getElectricProductionEfficiency(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-生产情况-风电/光伏时间利用率", description = "生产经营-生产情况-风电/光伏时间利用率")
    @GetMapping(value = "/operation/production/utilization-rate")
    public ApiResponse<List<NeTimeUtilizationRateVO>> getTimeUtilizationRate(@RequestParam(value = "year", required = false) Integer year) {
        List<NeTimeUtilizationRateVO> resultList = neProdoperTimeRateService.getTimeUtilizationRate(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-动态电价情况-蒙东实时电价", description = "生产经营-动态电价情况-蒙东实时电价")
    @GetMapping(value = "/operation/electric-price/east")
    public ApiResponse<List<NeEastElectricPriceVO>> getEastElectricPrice(@RequestParam(value = "year", required = false) Integer year) {
        List<NeEastElectricPriceVO> resultList = neProdoperEastPriceService.getEastElectricPrice(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-动态电价情况-蒙西实时电价", description = "生产经营-动态电价情况-蒙西实时电价")
    @GetMapping(value = "/operation/electric-price/west")
    public ApiResponse<List<NeEastElectricPriceVO>> getWestElectricPrice(@RequestParam(value = "year", required = false) Integer year) {
//        List<NeEastElectricPriceVO> resultList = neProdoperWestPriceService.getWestElectricPrice(year);
        List<NeEastElectricPriceVO> resultList = neProdoperEastPriceService.getWestElectricPrice(year);

        return ApiResponse.succeed(resultList);
    }


    @Operation(summary = "生产经营-销售情况-营收情况", description = "生产经营-销售情况-营收情况")
    @GetMapping(value = "/operation/sales/income")
    public ApiResponse<List<NeSalesIncomeVO>> getSalesIncome(@RequestParam(value = "year", required = false) Integer year) {
        List<NeSalesIncomeVO> resultList = neProdoperSalesIncomeService.getSalesIncome(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "生产经营-销售情况-购网电量", description = "生产经营-销售情况-购网电量")
    @GetMapping(value = "/operation/sales/purchase")
    public ApiResponse<List<NeSalesPurchaseVO>> getSalesPurchase(@RequestParam(value = "year", required = false) Integer year) {
        List<NeSalesPurchaseVO> resultList = neProdoperSalesPurchaseService.getSalesPurchase(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "产业指标-产业顶部指标", description = "产业指标-产业顶部指标")
    @GetMapping(value = "/overview/main-indicators")
    public ApiResponse<NeOverviewIndicatorsVO> getMainIndicators(@RequestParam(value = "year", required = false) Integer year) {
        NeOverviewIndicatorsVO vo = neOverviewItemService.getMainIndicators(year);
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "运行监测-设备状态监测-设备总体运行情况", description = "运行监测-设备状态监测-设备总体运行情况")
    @GetMapping(value = "/monitor/equipment/overview")
    public ApiResponse<NeEquipmentOverviewVO> getEquipmentOverview(@RequestParam(value = "year", required = false) Integer year) {
        NeEquipmentOverviewVO vo = neOpermonEqpStateService.getEquipmentOverview(year);
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "运行监测-设备状态监测-风电设备状态", description = "运行监测-设备状态监测-风电设备状态")
    @GetMapping(value = "/monitor/equipment/wind-status")
    public ApiResponse<NeWindEquipmentStatusVO> getWindEquipmentStatus(@RequestParam(value = "year", required = false) Integer year) {
        NeWindEquipmentStatusVO vo = neOpermonWindStateService.getWindEquipmentStatus(year);
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "运行监测-设备状态监测-光伏设备状态", description = "运行监测-设备状态监测-光伏设备状态")
    @GetMapping(value = "/monitor/equipment/pv-status")
    public ApiResponse<NePvEquipmentStatusVO> getPvEquipmentStatus(@RequestParam(value = "year", required = false) Integer year) {
        NePvEquipmentStatusVO vo = neOpermonPvStateService.getPvEquipmentStatus(year);
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "运行监测-电厂运行监测-总实时负荷", description = "运行监测-电厂运行监测-总实时负荷")
    @GetMapping(value = "/monitor/plant/real-time-load")
    public ApiResponse<List<NeRealTimeLoadVO>> getRealTimeLoad(@RequestParam(value = "year", required = false) Integer year) {
        List<NeRealTimeLoadVO> resultList = neOpermonRtLoadService.getRealTimeLoad(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "运行监测-电厂运行监测-光伏实时功率", description = "运行监测-电厂运行监测-光伏实时功率")
    @GetMapping(value = "/monitor/plant/pv-real-power")
    public ApiResponse<List<NePvRealPowerVO>> getPvRealPower(@RequestParam(value = "year", required = false) Integer year) {
        List<NePvRealPowerVO> resultList = neOpermonRtPvService.getPvRealPower(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "运行监测-电厂运行监测-风电实时功率", description = "运行监测-电厂运行监测-风电实时功率")
    @GetMapping(value = "/monitor/plant/wind-real-power")
    public ApiResponse<List<NeWindRealPowerVO>> getWindRealPower(@RequestParam(value = "year", required = false) Integer year) {
        List<NeWindRealPowerVO> resultList = neOpermonRtWindService.getWindRealPower(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "安全环保-节煤减排量", description = "安全环保-节煤减排量")
    @GetMapping(value = "/safe/environment/coal-reduction")
    public ApiResponse<List<NeCoalReductionVO>> getCoalReduction(@RequestParam(value = "year", required = false) Integer year) {
        List<NeCoalReductionVO> resultList = neSafetyenvCoalReduceService.getCoalReduction(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "运行监测-高风险作业", description = "运行监测-高风险作业")
    @GetMapping(value = "/safe/environment/high-risk-work")
    public ApiResponse<List<NeHighRiskWorkVO>> getHighRiskWork(@RequestParam(value = "year", required = false) Integer year) {
        List<NeHighRiskWorkVO> resultList = neSafetyenvRiskTaskService.getHighRiskWork(year);
        return ApiResponse.succeed(resultList);
    }

    @Operation(summary = "安全环保-互联网+平台应用排名", description = "安全环保-互联网+平台应用排名")
    @GetMapping(value = "/safe/environment/platform-ranking")
    public ApiResponse<List<NePlatformRankingVO>> getPlatformRanking(@RequestParam(value = "year", required = false) Integer year) {
        List<NePlatformRankingVO> resultList = neSafetyenvNetRankService.getPlatformRanking(year);
        return ApiResponse.succeed(resultList);
    }


    @Operation(summary = "新能源公司简介", description = "风电公司简介")
    @GetMapping(value = "/wind/company/intro")
    public ApiResponse<WindCompanyIntroVO> getWindCompanyIntro(@RequestParam(value = "orgCode", required = false) String orgCode) {
//        WindCompanyIntroVO vo =  windCompanyIntroService.getWindCompanyIntro(orgCode);
        // Mock数据
        WindCompanyIntroVO vo = new WindCompanyIntroVO();
        if("180063".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("达拉特旗那仁太新能源有限公司");
        } else if("134058".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("内蒙古察哈尔新能源有限公司");
        } else if("191364".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("内蒙古大板新能源有限公司");
        } else if("180056".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("阿巴嘎旗绿能新能源有限公司");
        } else if("134069".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("阿拉善右旗电投新能源有限公司");
        } else if("134059".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("内蒙古巴音新能源有限公司");
        }else if("191367".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("通辽市青格洱新能源有限公司道老杜分公司");
        } else if("180038".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("蒙东协合开鲁风力发电有限公司");
        } else if("191366".equalsIgnoreCase(orgCode)) {
            vo.setCompanyName("通辽市青格洱新能源有限公司珠日河分公司");
        }

        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "风电场基本信息", description = "风电场基本信息")
    @GetMapping(value = "/wind/field/basic-info")
    public ApiResponse<WindFieldBasicInfoVO> getWindFieldBasicInfo(@RequestParam(value = "orgCode", required = false) String orgCode) {
        // Mock数据
        WindFieldBasicInfoVO vo =  windFieldBasicInfoService.getWindFieldBasicInfo(orgCode);
//        WindFieldBasicInfoVO vo = new WindFieldBasicInfoVO();
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "风电安全环保", description = "风电安全环保")
    @GetMapping(value = "/wind/safety-env")
    public ApiResponse<WindSafetyEnvVO> getWindSafetyEnv(@RequestParam(value = "orgCode", required = false) String orgCode) {
        // Mock数据
        WindSafetyEnvVO vo = nePopupSafeService.getWindSafetyEnv(orgCode);
//        WindSafetyEnvVO vo = new WindSafetyEnvVO();

        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "风电发电情况", description = "风电发电情况")
    @GetMapping(value = "/wind/power-generation")
//    TODO 接口存在问题
    public ApiResponse<WindPowerGenerationVO> getWindPowerGeneration(@RequestParam(value = "orgCode", required = false) String orgCode) {
        // Mock数据 NeProdoperPowerGs
        WindPowerGenerationVO vo  = neProdoperPowerGsService.getWindPowerGeneration(orgCode);
//        WindPowerGenerationVO vo = new WindPowerGenerationVO();
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "风电资源", description = "风电资源")
    @GetMapping(value = "/wind/resource")
    public ApiResponse<WindResourceVO> getWindResource(@RequestParam(value = "orgCode", required = false) String orgCode) {
        // Mock数据
        WindResourceVO vo = neWindResourceService.getWindResource(orgCode);
//        WindResourceVO vo = new WindResourceVO();
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "风电实时功率", description = "风电实时功率")
    @GetMapping(value = "/wind/real-time-power")
//   TODO 光伏 qt_dp_ne_opermon_rt_pv   realtime_power  风电 qt_dp_ne_opermon_rt_wind  realtime_power
    public ApiResponse<WindRealTimePowerVO> getWindRealTimePower(@RequestParam(value = "orgCode", required = false) String orgCode) {
        // Mock数据
        WindRealTimePowerVO vo = neOpermonRtPvService.getWindRealTimePower(orgCode);
//        WindRealTimePowerVO vo = new WindRealTimePowerVO();
        return ApiResponse.succeed(vo);
    }

    @Operation(summary = "风电上网及购网电量", description = "风电上网及购网电量")
    @GetMapping(value = "/wind/grid-power")
    public ApiResponse<WindGridPowerVO> getWindGridPower(@RequestParam(value = "orgCode", required = false) String orgCode) {
        // Mock数据
//        WindGridPowerVO vo = new WindGridPowerVO();
        WindGridPowerVO vo = nePopupNetOutputService.getWindGridPower(orgCode);
        return ApiResponse.succeed(vo);
    }

}
